package com.gdqy.FCS.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.gdqy.FCS.entity.Dictionary;
import com.gdqy.FCS.entity.DictionaryType;
import com.gdqy.FCS.service.DictionaryService;
import com.gdqy.FCS.service.DictionaryTypeService;

@Controller
@RequestMapping("dictionary")
public class DictionaryController {
	
	@Autowired
	private DictionaryService dictionaryService;
	@Autowired
	private DictionaryTypeService dictionaryTypeService;
	
	@RequestMapping("admin_dictionary")
	public ModelAndView admin_dictionary() {
		ModelAndView modelAndView = new  ModelAndView();
		List<DictionaryType> dictionaryTypes = dictionaryTypeService.selectAll();
		modelAndView.addObject("dictionaryTypes", dictionaryTypes);
		List<Dictionary> dictionaries = dictionaryService.selectAll();
		modelAndView.addObject("dictionaries", dictionaries);
		modelAndView.setViewName("admin/dictionary");
		return modelAndView;
	}
	@RequestMapping("add_dictionary")
	public @ResponseBody String add_dictionary(Dictionary dictionary) {
		String msg = "fail";
		int data = dictionaryService.insert(dictionary);
		if(data>0) {
			msg="success";
		}
		return msg;
	}
}
